package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: qian
 * Date: 2023-01-02
 * Time: 18:17
 */
public class Demo10 {
    public static void main(String[] args) {
        Object object=new Object();

        Thread t1=new Thread(()->{
            while(true){
                synchronized(object) {
                    System.out.println("wait之前");
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println("wait之后");
                }
            }
        });
        t1.start();
        Thread t2=new Thread(()->{
            while (true){
                synchronized (object){
                    System.out.println("notify之前");
                    object.notify();
                    System.out.println("notify之后");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });

        t2.start();
    }
}
